package LRES;

import java.util.List;

public class Coefficient {
	private int inputNum;                                            //输入层神经元数目
	private int hideNum;                                              //隐层神经元数目，前馈网络隐藏层
	private int outputNum;                                               //输出层神经元数目
	private double hideWeight[][];    //输入层至隐层权值
	private double outWeight[][];          //隐层至输出层权值
	private double hideThreshold[];                       //隐层的阈值
	private double outputThreshold[];                        //输出层的阈值
	private double hideIn[];                           //隐层的输入,各个隐藏层的神经单元的内积,Sigmod函数所处理的参数
	private double outputIn[];                            //输出层的输入，各个输出层的神经单元的内积，Sigmod函数所处理的参数
	private double hide[];                           //隐层的输出，s型函数之后的输出值
	private double output[];                            //输出层的输出，s型函数之后的输出值
	private double alpha;                                             //动量因子，改进型bp算法使用 
	private double error;                          //样本的整体误差（参见PDF）
	private double a;                                                 //输出层至隐层学习效率，反向传播，误差分析时用到
	private double b;                                                 //隐层至输入层学习效率，反向传播，误差分析时用到
	private double outputErr[];                        //δk 输出层与隐层变化量：(期望输出-实际输出)*f'(输出层输入)
	private double hideErr[];                       //δj 输入层与隐藏层变化量：(期望输出-实际输出)*f'(输出层输入)
	private double oldHide[][];             //新旧权值更新量交替--改进型Bp算法       
	private double oldOutput[][];
	private double hideWeightTemp[][]; // 保存前一组输入层到隐层的权值
	private double outWeightTemp[][]; // 保存前一组隐层到输出层的权值
	private double hideThresholdTemp[];     //保存前一组隐层的阈值
	private double outputThresholdTemp[];   //保存前一组输出层的阈值
	private List<double[]> sample;       //样本
	private double precision;          //精度
	private int counter;    //训练次数
	private int times;     //训练次数边界
	private double[] input;//需要计算的输入

	public Coefficient(int inputnum,int hidenum,int outputnum,double a,double b,double alpha,double precision,int times){
		this.inputNum=inputnum;
		this.hideNum=hidenum;
		this.outputNum=outputnum;
		this.a=a;
		this.b=b;
		this.alpha=alpha;
		this.precision=precision;
		this.times=times;
		initParameters();
	}

	/**
	 * 初始化各数组
	 */
	private void initParameters(){
		this.sample=Samples.getWarrantySample();
		hideWeight = new double[inputNum][hideNum];
		outWeight = new double[hideNum][outputNum];
		hideWeightTemp=new double[inputNum][hideNum];
		outWeightTemp=new double[hideNum][outputNum];
		hideThreshold = new double[hideNum];
		hideThresholdTemp=new double[hideNum]; 
		outputThreshold = new double[outputNum];
		outputThresholdTemp=new double[outputNum];
		hideIn = new double[hideNum];
		outputIn = new double[outputNum];
		hide = new double[hideNum];
		output = new double[outputNum];
		outputErr = new double[outputNum];
		hideErr = new double[hideNum];
		oldHide = new double[inputNum][hideNum];       
		oldOutput = new double[hideNum][outputNum];
	}

	@Override
	public String toString() {
		StringBuilder sb=new StringBuilder();
		sb.append("输入节点：").append(inputNum)
		.append("\n中间节点：").append(hideNum)
		.append("\n输出节点：").append(outputNum)
		.append("\n输出：").append(output[0])
		.append("\n训练次数边界：").append(times)
		.append("\n训练次数：").append(counter)
		.append("\n误差边界：").append(precision)
		.append("\n实际误差：").append(error);
		boolean flag=(precision-error)>0;
		sb.append("\n实际误差是否小于误差边界：").append(flag);
		return sb.toString();
	}

	/*get、set方法*/
	public int getInputNum() {
		return inputNum;
	}
	public void setInputNum(int inputNum) {
		this.inputNum = inputNum;
	}
	public int getHideNum() {
		return hideNum;
	}
	public void setHideNum(int hideNum) {
		this.hideNum = hideNum;
	}
	public int getOutputNum() {
		return outputNum;
	}
	public void setOutputNum(int outputNum) {
		this.outputNum = outputNum;
	}

	public double[][] getHideWeight() {
		return hideWeight;
	}
	public void setHideWeight(double[][] input2HideWeight) {
		hideWeight = input2HideWeight;
	}
	public double[][] getOutWeight() {
		return outWeight;
	}
	public void setOutWeight(double[][] hide2OutWeight) {
		outWeight = hide2OutWeight;
	}
	public double[] getHideThreshold() {
		return hideThreshold;
	}
	public void setHideThreshold(double[] hideThreshold) {
		this.hideThreshold = hideThreshold;
	}
	public double[] getOutputThreshold() {
		return outputThreshold;
	}
	public void setOutputThreshold(double[] outputThreshold) {
		this.outputThreshold = outputThreshold;
	}
	public double[] getHideIn() {
		return hideIn;
	}
	public void setHideIn(double[] hideIn) {
		this.hideIn = hideIn;
	}
	public double[] getOutputIn() {
		return outputIn;
	}
	public void setOutputIn(double[] outputIn) {
		this.outputIn = outputIn;
	}
	public double[] getHide() {
		return hide;
	}
	public void setHide(double[] hide) {
		this.hide = hide;
	}
	public double[] getOutput() {
		return output;
	}
	public void setOutput(double[] output) {
		this.output = output;
	}
	public double getAlpha() {
		return alpha;
	}
	public void setAlpha(double alpha) {
		this.alpha = alpha;
	}
	public double getError() {
		return error;
	}
	public void setError(double error) {
		this.error = error;
	}
	public double getA() {
		return a;
	}
	public void setA(double a) {
		this.a = a;
	}
	public double getB() {
		return b;
	}
	public void setB(double b) {
		this.b = b;
	}
	public double[] getOutputErr() {
		return outputErr;
	}
	public void setOutputErr(double[] outputErr) {
		this.outputErr = outputErr;
	}
	public double[] getHideErr() {
		return hideErr;
	}
	public void setHideErr(double[] hideErr) {
		this.hideErr = hideErr;
	}
	public double[][] getOldHide() {
		return oldHide;
	}
	public void setOldHide(double[][] oldHide) {
		this.oldHide = oldHide;
	}
	public double[][] getOldOutput() {
		return oldOutput;
	}
	public void setOldOutput(double[][] oldOutput) {
		this.oldOutput = oldOutput;
	}

	public List<double[]> getSample() {
		return sample;
	}

	public void setSample(List<double[]> sample) {
		this.sample = sample;
	}

	public double getPrecision() {
		return precision;
	}

	public void setPrecision(double precision) {
		this.precision = precision;
	}

	public int getCounter() {
		return counter;
	}

	public void setCounter(int counter) {
		this.counter = counter;
	}

	public void setTimes(int times) {
		this.times = times;
	}

	public int getTimes() {
		return times;
	}

	public void setInput(double[] input) {
		this.input = input;
	}

	public double[] getInput() {
		return input;
	}

	public double[][] getHideWeightTemp() {
		return hideWeightTemp;
	}

	public void setHideWeightTemp(double[][] hideWeightTemp) {
		this.hideWeightTemp = hideWeightTemp;
	}

	public double[][] getOutWeightTemp() {
		return outWeightTemp;
	}

	public void setOutWeightTemp(double[][] outWeightTemp) {
		this.outWeightTemp = outWeightTemp;
	}

	public double[] getHideThresholdTemp() {
		return hideThresholdTemp;
	}

	public void setHideThresholdTemp(double[] hideThresholdTemp) {
		this.hideThresholdTemp = hideThresholdTemp;
	}

	public double[] getOutputThresholdTemp() {
		return outputThresholdTemp;
	}

	public void setOutputThresholdTemp(double[] outputThresholdTemp) {
		this.outputThresholdTemp = outputThresholdTemp;
	}
}
